{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=414
  Verdict: Accepted
}
uses SysUtils, Math;
 
type
	unt=record
		v:int64;
		n:longint;
	end;
 
var
	i,n,m,l,r,ans,c,kk,cur:longint;
	a,b:array[0..100010] of unt;
	f:boolean;
 
procedure sort(var a:array of unt; l,r:longint);
var
	i,j,x:longint;
	y:unt;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2].v;
repeat
	while a[i].v<x do inc(i);
	while a[j].v>x do dec(j);
	if i<=j then begin
		y:=a[i];
		a[i]:=a[j];
		a[j]:=y;
		inc(i);
		dec(j);
	end;
until i>j;
if l<j then sort(a,l,j);
if i<r then sort(a,i,r);
end;
 
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(n,m);
for i:=1 to n do begin
	read(a[i].v);
	a[i].n:=i;
end;
for i:=1 to m do begin
	read(b[i].v);
	b[i].n:=i;
end;
sort(a,1,n);
sort(b,1,m);
l:=0;
r:=min(n,m div 2)+1;
ans:=0;
while r-l>1 do begin
	c:=(l+r) div 2;
	kk:=0;
	cur:=1;
	while kk<c do begin
		f:=false;
		for i:=cur to n do
			if (a[i].v>b[kk+1].v) and (a[i].v<b[kk+1+m-c].v) then begin
				f:=true;
				inc(kk);
				cur:=i+1;
				break;
			end;
		if not f then break;
	end;
	if kk>=c then begin
		ans:=c;
		l:=c;
	end else r:=c;
end;
writeln(ans);
c:=ans;
kk:=0;
cur:=1;
while kk<c do begin
	for i:=cur to n do
		if (a[i].v>b[kk+1].v) and (a[i].v<b[kk+1+m-c].v) then begin
			writeln(a[i].n,' ',b[kk+1].n,' ',b[kk+1+m-c].n);
			inc(kk);
			cur:=i+1;
			break;
		end;
	end;
end.